package StreamingServer;

public class ByteTesting {
	
	  static int HEADER_SIZE = 12;
		  
	  //Bitstream of the RTP header
	  public static byte[] header;
	  
	  //Bitstream of the RTP payload
	  public static byte[] payload;
	  
	  
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		byte[] inpByte ={1,0,1,0,1,0,1,0};
		
		RTPpacket(26,1, 1,inpByte,2);
	}
	
	  public static void RTPpacket(int PType, int Framenb, int Time, byte[] data, int data_length){
		    //fill by default header fields:
		   int Version = 2;
		   int Padding = 0;
		   int Extension = 0;
		   int CC = 0;
		   int Marker = 0;
		   int Ssrc = 0;

		    //fill changing header fields:
		    int SequenceNumber = Framenb;
		    int TimeStamp = Time;
		    int PayloadType = PType;
		    
		    //build the header bistream:
		    //--------------------------
		    header = new byte[HEADER_SIZE];

		    //.............
		    //TO COMPLETE
		    //.............
		    //fill the header array of byte with RTP header fields

		    header[0] = (byte) (header[0] | Version << 6);
		    header[0] = (byte) (header[0] | Padding << 5);
		    header[0] = (byte) (header[0] | Extension << 4);
		    header[0] = (byte) (header[0] | CC <<0);
		    
		    header[1] = (byte) (header[1] | Marker << 7);
		    header[1] = (byte) (header[1] | PayloadType << 0);

		    header[2] = (byte) (header[2] | SequenceNumber >> 7);
		    header[3] = (byte) (header[3] | SequenceNumber <<0);
		    
		    header[4] = (byte) (header[4] | TimeStamp >>24);
		    header[5] = (byte) (header[5] | TimeStamp >>15);
		    header[6] = (byte) (header[6] | TimeStamp >>7);
		    header[7] = (byte) (header[7] | TimeStamp >>0);
		    
		    header[8] = (byte) (header[8] | Ssrc >>24);
		    header[9] = (byte) (header[9] | Ssrc >>15);
		    header[10] = (byte) (header[10] | Ssrc >>7);
		    header[11] = (byte) (header[11] | Ssrc >>0);
		    
		    //fill the payload bitstream:
		    //--------------------------
		    int payload_size = data_length;
		    payload = new byte[data_length];

		    //fill payload array of byte from data (given in parameter of the constructor)
		    payload = data;
		    		    
		    // ! Do not forget to uncomment method printheader() below !
		    printheader();

		  }
	  
	  //print headers without the SSRC
	  //--------------------------
	  public static void printheader()
	  {
	    
	    for (int i=0; i < (HEADER_SIZE-4); i++)
	      {
		for (int j = 7; j>=0 ; j--)
		  if (((1<<j) & header[i] ) != 0)
		    System.out.print("1");
		else
		  System.out.print("0");
		System.out.print(" ");
	      }

	    System.out.println();
	    
	  }

}
